//
//  HomeFloorCell3.swift
//  WeiBoAPP
//
//  Created by ios001 on 2021/6/15.
//  Copyright © 2021 zxf. All rights reserved.
//

import UIKit

// 1、定义协议
protocol HomeFloorCell3Delegate :NSObjectProtocol{
    //2、定义协议方法
    func HomeFloorDidSelectAction(model:HomeModel)
}




class HomeFloorCell3: UITableViewCell {

    // 声明block
    typealias HomeFloorCell3DidSelectBlock = (HomeModel)->Void
    //定义
    typealias SelectBlock = (_ str:String)->Void
    
    //声明
    var cellDidSelectBlock:HomeFloorCell3DidSelectBlock?
    var sblock:SelectBlock?
    
    // 声明代理
    weak var mDelegate:HomeFloorCell3Delegate?
    
    
    
    
    @IBOutlet weak var bgView1: UIView!
    @IBOutlet weak var bgView2: UIView!
    @IBOutlet weak var bgView3: UIView!
    
    
    @IBOutlet weak var leftImage: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    
    @IBOutlet weak var actionLabel: UILabel!
    
    @IBOutlet weak var image2: UIImageView!
    @IBOutlet weak var titleLabel2: UILabel!
    @IBOutlet weak var activityLabel2: UILabel!
    
    @IBOutlet weak var image3: UIImageView!
    @IBOutlet weak var title3: UILabel!
    @IBOutlet weak var activityLabel3: UILabel!
    
    var model:HomeModel?{
        didSet {
            titleLabel.text = model?.title;
            actionLabel.text = model?.module;
            
            titleLabel2.text = model?.title;
            activityLabel2.text = model?.module;
            
            title3.text = model?.title;
            activityLabel3.text = model?.module;
            
        }
    }
    

    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(itemActionTap))
        bgView1.addGestureRecognizer(tap)
        bgView1.tag = 10
        let tap2 = UITapGestureRecognizer.init(target: self, action: #selector(itemActionTap))
        bgView2.addGestureRecognizer(tap2)
        bgView2.tag = 11
        let tap3 = UITapGestureRecognizer.init(target: self, action: #selector(itemActionTap))
        bgView3.addGestureRecognizer(tap3)
        bgView3.tag = 12
        
    }

    // 监听事件
    @objc private func itemActionTap(tap:UITapGestureRecognizer) -> () {
        
        let tag = tap.view?.tag
        
        if tag == 10 {
//            Force-unwrap使用”!'来终止执行，如果可选值包含'nil'
            mDelegate?.HomeFloorDidSelectAction(model: model!)
            
        } else if tag == 11 {
            
            self.cellDidSelectBlock?(model!)
            
        }else if tag == 12 {
            self.sblock?("xxx")
        
            
        }
        
        print("打印字符串")
        
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
